package com.tengfei.blogsystem;


import com.tengfei.blogsystem.utils.JwtUtil;
import com.tengfei.blogsystem.utils.RedisUtil;
import io.jsonwebtoken.Claims;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.DigestUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @version v1.0
 * @author} feige
 * @date 2021-10-17-14:59
 * @description
 */
@SpringBootTest
public class test {

    @Autowired
    RedisUtil redisUtil;

    @Autowired
    RedisTemplate redisTemplate;

    @Test
    public void test01() {
        redisUtil.set("hello", "飞哥");
    }

    @Test
    public void test02() {
        redisTemplate.opsForValue().set("hello2", "feige");
    }

    @Test
    public void test03() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", "899408341250342912");
        map.put("userName", "feige");
        String token = JwtUtil.createToken(map);
//        String token = JwtUtil.createRefreshToken("899408341250342912", 3 * 60 * 60);
        System.out.println(token);
    }

    @Test
    public void test04() {
        String md5DigestAsHex = DigestUtils.md5DigestAsHex("blogsystem".getBytes());
        System.out.println(md5DigestAsHex);
    }

    @Test
    public void test05() {
        Claims claims = JwtUtil.parseJWT("eyJhbGciOiJIUzI1NiJ9.eyJpZCI6Ijg5OTQwODM0MTI1MDM0MjkxMiIsInVzZXJOYW1lIjoiZmVpZ2UiLCJleHAiOjE2MzQ1MTYxOTl9.UCBxNCdLVrEHIhhOrvJmEOUmnbfrcEWMKs1WDW0xGWo");
        String id = claims.getId();
        Object id1 = claims.get("id");
        System.out.println(id);
        System.out.println(id1);
    }
}
